package com.fxb.learn.direct_buff.channels;

import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @author fangjiaxiaobai
 * @date 2022-05-29 10:07
 */
public class FileChannelDemo {


    public static void main(String[] args) throws IOException {
        FileChannel fc = FileChannel.open(Paths.get("/Users/wangxiyue/Documents/fxb_application/learn_java/fxb_jdk11/ch11-nio_demo/target/classes/com/fxb/learn/direct_buff/demo.txt"), StandardOpenOption.READ);

        MappedByteBuffer map = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());

        int size = (int) fc.size();
        byte[] bytes = new byte[size];
        map.get(bytes);
        System.out.println(new String(bytes));
    }
}
